home *** CD-ROM | disk | FTP | other *** search
/ Robotics & Artificial Int…3 (Professional Edition) / Robotics & Artificial Intelligence Tools 2003 (Professional Edition).iso / neural network tool and application / nsinstall.exe / data1.cab / DllSys_Files / FULLSYN / BKFULLS.C next >
Encoding:
C/C++ Source or Header  |  2002-03-08  |  2.3 KB  |  62 lines

  1. // Dynamic link library implementation of NeuroSolutions BackFullSynapse component 
  2.  
  3. #include "NSDLL.h"
  4.  
  5. /*************************************************************/
  6. /* Macros to access the PE layers and weights in matrix form */
  7.  
  8. #define in(i,j)        errorIn[j+i*inCols]
  9. #define out(i,j)    errorOut[j+i*outCols]
  10. #define W(i,j)        weights[j+i*outCount]
  11. #define Wg(i,j)        gradients[j+i*outCount]
  12.  
  13. /********************************/
  14. /* Backpropagation of component */
  15.  
  16. __declspec(dllexport) void performBackFullSynapse(
  17.     DLLData *instance,    // Pointer to instance data (may be NULL)
  18.     DLLData *dualInstance,    // Pointer to the forward synapses instance data (may be NULL)
  19.     NSFloat    *errorIn,     // Pointer to the input error layer of processing elements (PEs)
  20.     int     inRows,        // Number of rows of PEs in the input layer (don't forget that input and output are reversed)
  21.     int     inCols,        // Number of columns of PEs in the input layer
  22.     NSFloat    *errorOut,     // Pointer to the output error layer 
  23.     int     outRows,    // Number of rows of PEs in the output layer
  24.     int     outCols,    // Number of columns of PEs in the output layer
  25.     NSFloat    *input,     // Pointer to the output layer of the forward synapse
  26.     NSFloat    *weights,     // Pointer to the fully connected matrix of weights
  27.     NSFloat    *gradients     // Pointer to the weight gradient matrix 
  28.     )
  29. {
  30.     int    i, j,
  31.         inCount=inRows*inCols,
  32.         outCount=outRows*outCols;
  33.  
  34.     for (i=0; i<outCount; i++)
  35.         for (j=0; j<inCount; j++) {
  36.             errorOut[i] += W(j,i)*errorIn[j]; 
  37.             if (gradients)
  38.                 Wg(j,i) += errorIn[j]*input[i];
  39.         }    
  40. }
  41.  
  42. /******************************************/
  43. /* Management of instance data (OPTIONAL) */
  44. /*
  45. __declspec(dllexport) DLLData *allocBackFullSynapse(
  46.     DLLData    *oldInstance,    // Pointer to the last instance if reallocating
  47.     DLLData    *dualInstance,    // Pointer to forward axonÆs instance data (may be NULL)
  48.     int     inRows,        // Number of rows of PEs in the input layer
  49.     int     inCols,        // Number of columns of PEs in the input layer
  50.     int     outRows,    // Number of rows of PEs in the output layer
  51.     int     outCols        // Number of columns of PEs in the output layer
  52.     )
  53. {
  54.     DLLData *instance = allocDLLInstance(oldInstance);
  55.     return instance;
  56. }
  57.  
  58. __declspec(dllexport) void freeBackFullSynapse(DLLData *instance)
  59. {
  60.     freeDLLInstance(instance);
  61. }
  62. */